import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.AffineTransform;
import javax.swing.*;  

public class Demo extends Canvas {
    
        public double increment = 5.0;
        public int emphasis = 9;
    
        public Demo() {
            setBackground(Color.white);
        }
    
    
        public void drawDemo(int w, int h, Graphics2D g2) {
            int size = Math.min(w, h);
            float ew = size/4;
            float eh = size-20;
            Ellipse2D ellipse = new Ellipse2D.Float(-ew/2, -eh/2, ew, eh);

            /* 
             * from 0 to 360 degrees, increases the degrees by the
             * selected increment amount and renders the transformed ellipses
             */
            for (double angdeg = 0; angdeg < 360; angdeg+=increment) {

	        // set stroke to a wider stroke every emphasis degrees
                if (angdeg % emphasis == 0) {
                    g2.setColor(Color.gray);
                    g2.setStroke(new BasicStroke(2.0f));
                } else {
                    g2.setColor(Color.lightGray);
                    g2.setStroke(new BasicStroke(0.5f));
                }
                AffineTransform at = AffineTransform.getTranslateInstance(w/2, h/2);
                at.rotate(Math.toRadians(angdeg));
                g2.draw(at.createTransformedShape(ellipse));
            }

            // renders the blue and yellow ellipses in the center
            g2.setColor(Color.blue);
            ellipse.setFrame(w/2-10,h/2-10,20,20);
            g2.fill(ellipse);
            g2.setColor(Color.gray);
            g2.setStroke(new BasicStroke(6));
            g2.draw(ellipse);
            g2.setColor(Color.yellow);
            g2.setStroke(new BasicStroke(4));
            g2.draw(ellipse);
            g2.setColor(Color.black);
            g2.drawString("Rotate", 5, 15);
        }
    
    
        public void paint(Graphics g) {
            Graphics2D g2 = (Graphics2D) g;
            Dimension d = getSize();
            g2.setBackground(getBackground());
            g2.clearRect(0, 0, d.width, d.height);
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            drawDemo(d.width, d.height, g2);
        }
    } // End Demo class